package com.txh.blog.controller.resMe;

import com.txh.blog.exceprtion.exceptions.NullAttrException;
import com.txh.blog.model.Resme;
import com.txh.blog.service.ResMeservice;
import com.txh.blog.util.ResultJsonUtils;
import com.txh.blog.vo.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("resme")
public class ResMeController {

    @Autowired
    private ResMeservice resMeservice;
    @RequestMapping("/me")
    public String resMe(Model model){
        Resme resme = resMeservice.resMes();
        model.addAttribute("me",resme);
        return "admin/resMe";
    }

    @RequestMapping("/save")
    @ResponseBody
    public ResultJson add(Resme resme){
        if (resme == null){
            throw new NullAttrException();
        }
        resMeservice.save(resme);
        return ResultJsonUtils.success(null);
    }
}
